package com.lyeducation.util.aLiYunOss;


import java.util.HashMap;
import java.util.Map;

public class RequestInfoUtil {
    public static Map<String, Object> requestUtil(String request) {
        Map<String, Object> map = new HashMap<String, Object>();
        strRequest(map, request);
        return map;
    }

    public static String strRequest(Map<String, Object> map, String s) {
        int index1 = s.indexOf("=");
        String parm1 = s.substring(0, index1);
        int index2 = s.indexOf("&");
        String parm2 = "";
        if (index2 == -1) {
            parm2 = s.substring(index1 + 1);
            if (parm2 instanceof String) {
                if (parm2.startsWith("\"")) {
                    parm2 = parm2.substring(parm2.indexOf("\"") + 1, parm2.length());
                }
                if (parm2.endsWith("\"")) {
                    parm2 = parm2.substring(0, parm2.lastIndexOf("\""));
                }
            }
            map.put(parm1, parm2);
            return null;
        }
        parm2 = s.substring(index1 + 1, index2);
        if (parm2 instanceof String) {
            if (parm2.startsWith("\"")) {
                parm2 = parm2.substring(parm2.indexOf("\"") + 1, parm2.length());
            }
            if (parm2.endsWith("\"")) {
                parm2 = parm2.substring(0, parm2.lastIndexOf("\""));
            }
        }
        map.put(parm1, parm2);
        return strRequest(map, s.substring(index2 + 1));
    }
}
